﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace JqueryNet.FormControl.FormWebControl
{
    public class JRadioButton : JWebControl
    {
        RadioButton radioButton;
        public JRadioButton(RadioButton radioButton) : base(radioButton) { this.radioButton = radioButton; }

        public override void Attr(string key)
        {
            switch (key.ToLower())
            {
                case "title":
                case "tooltip":
                    Value = radioButton.ToolTip;
                    return;
                case "width":
                    Value = radioButton.Width;
                    return;
                case "height":
                    Value = radioButton.Height;
                    return;
                case "checked":
                    Value = radioButton.Checked;
                    return;
                default:
                    base.Attr(key); return;
            }
        }

        public override void Attr(string key, string value)
        {
            bool f;
            bool.TryParse(value, out f);
            int b;
            int.TryParse(value, out b);
            switch (key.ToLower())
            {
                case "title":
                case "tooltip":
                    radioButton.ToolTip = value;
                    return;
                case "width":
                    radioButton.Width = b;
                    return;
                case "height":
                    radioButton.Height = b;
                    return;
                case "checked":
                    radioButton.Checked = f;
                    return;
                default:
                    base.Attr(key, value); return;
            }
        }

        public override void Val()
        {
            Value = radioButton.Text;
        }

        public override void Val(string value)
        {
            radioButton.Text = value;
        }
    }
}
